using System;
using System.Drawing;
using System.Windows.Forms;

namespace WebView2Project
{
    public partial class JavaScriptForm : Form
    {
        public string JavaScriptCode { get; private set; }

        public JavaScriptForm()
        {
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            this.txtScript = new System.Windows.Forms.TextBox();
            this.btnExecute = new System.Windows.Forms.Button();
            this.btnCancel = new System.Windows.Forms.Button();
            this.lblInstruction = new System.Windows.Forms.Label();
            this.lblExamples = new System.Windows.Forms.Label();
            this.SuspendLayout();
            
            // 
            // lblInstruction
            // 
            this.lblInstruction.AutoSize = true;
            this.lblInstruction.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Bold);
            this.lblInstruction.Location = new System.Drawing.Point(12, 15);
            this.lblInstruction.Name = "lblInstruction";
            this.lblInstruction.Size = new System.Drawing.Size(200, 17);
            this.lblInstruction.TabIndex = 0;
            this.lblInstruction.Text = "请输入要执行的JavaScript代码：";
            
            // 
            // txtScript
            // 
            this.txtScript.Font = new System.Drawing.Font("Consolas", 10F);
            this.txtScript.Location = new System.Drawing.Point(15, 45);
            this.txtScript.Multiline = true;
            this.txtScript.Name = "txtScript";
            this.txtScript.ScrollBars = System.Windows.Forms.ScrollBars.Both;
            this.txtScript.Size = new System.Drawing.Size(557, 200);
            this.txtScript.TabIndex = 1;
            this.txtScript.Text = "// 示例：获取页面标题\r\ndocument.title";
            
            // 
            // lblExamples
            // 
            this.lblExamples.AutoSize = true;
            this.lblExamples.Font = new System.Drawing.Font("Microsoft YaHei UI", 8.25F);
            this.lblExamples.ForeColor = System.Drawing.Color.Gray;
            this.lblExamples.Location = new System.Drawing.Point(15, 255);
            this.lblExamples.Name = "lblExamples";
            this.lblExamples.Size = new System.Drawing.Size(500, 80);
            this.lblExamples.TabIndex = 2;
            this.lblExamples.Text = "示例代码：\r\n" +
                "• document.title - 获取页面标题\r\n" +
                "• window.location.href - 获取当前URL\r\n" +
                "• alert('Hello from C#!') - 显示警告框\r\n" +
                "• browserHost.showMessage('Hello from JavaScript!') - 调用C#方法\r\n" +
                "• browserHost.getCurrentTime() - 获取系统时间";
            
            // 
            // btnExecute
            // 
            this.btnExecute.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F);
            this.btnExecute.Location = new System.Drawing.Point(416, 350);
            this.btnExecute.Name = "btnExecute";
            this.btnExecute.Size = new System.Drawing.Size(75, 30);
            this.btnExecute.TabIndex = 3;
            this.btnExecute.Text = "执行";
            this.btnExecute.UseVisualStyleBackColor = true;
            this.btnExecute.Click += new System.EventHandler(this.btnExecute_Click);
            
            // 
            // btnCancel
            // 
            this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.btnCancel.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F);
            this.btnCancel.Location = new System.Drawing.Point(497, 350);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new System.Drawing.Size(75, 30);
            this.btnCancel.TabIndex = 4;
            this.btnCancel.Text = "取消";
            this.btnCancel.UseVisualStyleBackColor = true;
            
            // 
            // JavaScriptForm
            // 
            this.AcceptButton = this.btnExecute;
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.CancelButton = this.btnCancel;
            this.ClientSize = new System.Drawing.Size(584, 392);
            this.Controls.Add(this.btnCancel);
            this.Controls.Add(this.btnExecute);
            this.Controls.Add(this.lblExamples);
            this.Controls.Add(this.txtScript);
            this.Controls.Add(this.lblInstruction);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "JavaScriptForm";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
            this.Text = "执行JavaScript代码";
            this.ResumeLayout(false);
            this.PerformLayout();
        }

        private void btnExecute_Click(object sender, EventArgs e)
        {
            JavaScriptCode = txtScript.Text.Trim();
            if (string.IsNullOrWhiteSpace(JavaScriptCode))
            {
                MessageBox.Show("请输入JavaScript代码", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private System.Windows.Forms.TextBox txtScript;
        private System.Windows.Forms.Button btnExecute;
        private System.Windows.Forms.Button btnCancel;
        private System.Windows.Forms.Label lblInstruction;
        private System.Windows.Forms.Label lblExamples;
    }
} 